package com.kaifamiao.uploader.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;

@Data
public class Resp extends HashMap<String, Object> implements Serializable {

    public static Resp instance(int code, String message, Object data) {
        Resp r = new Resp();
        r.put("code", code);
        r.put("message", message);
        r.put("data", data);
        return r;
    }
    public static Resp success() {
        return instance(200, "操作成功", null);
    }

    public static Resp success(int code, String message) {
        return instance(code, message, null);
    }
    public static Resp success(String message) {
        return instance(200, message, null);
    }

    public static Resp success(Object data) {
        return instance(200,"操作成功", data);
    }


    public static Resp error() {
        return instance(500, "操作失败", null);
    }

    public static Resp error(String message) {
        return instance(500, message, null);
    }

    public static Resp error(int code, String message) {
        return instance(code, message, null);
    }

    public Resp put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}
